package vn.mobiistar.videoapp.fragment;

import vn.mobiistar.videoapp.activity.MainActivity;
import vn.mobiistar.videoapp.other.Define;
import vn.mobiistar.videoapp.other.Video;
import vn.mobiistar.videoapp.other.VideoAdapter;
import vn.mobiistar.videoapp.other.VideoPlayer;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;

import com.github.pedrovgs.DraggablePanel;

public abstract class BaseFragment extends Fragment{
	
	public VideoPlayer 			mPlayer;
	public int 					mRotation;
	public DraggablePanel 		draggablePanel;
	public boolean 				mIsInitialVideoPlayer;
	public int					mBackToFragment = 0;

	public VideoPlayer getPlayer() {
		return mPlayer;
	}

	public void setPlayer(VideoPlayer mPlayer) {
		this.mPlayer = mPlayer;
	}
	// goi moi khi user click vao video tren listview
	public void onVideoClick(AdapterView<?> parent, View view,int position, long id){
		Display display = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		mRotation = display.getRotation();
		if(draggablePanel != null) draggablePanel.setVisibility(View.VISIBLE);
		if(mPlayer.getYoutubePlayer() != null) if(mPlayer.isPlaying()){
			mPlayer.pause();
		}
		Video item = (Video) ((VideoAdapter) ((ListView) parent).getAdapter())
				.getItem(position);
		mPlayer.playVideo(item,mRotation,Define.DELAY_MAXIMIZE);
		if(mPlayer.mIsInitiated) mPlayer.getDraggablePanel().minimize();
		mIsInitialVideoPlayer = true;
		mPlayer.maximize();
	}
}
